//
//  HRAnswerListViewController.m
//  Hear
//
//  Created by mac on 2017/4/14.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "HRAnswerListViewController.h"
#import <DZNEmptyDataSet/UIScrollView+EmptyDataSet.h>

@interface HRAnswerListViewController ()<DZNEmptyDataSetSource,DZNEmptyDataSetDelegate>
@end

@implementation HRAnswerListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"会话列表";
    
//    UIButton *leftButton = [UIButton buttonWithType:0];
//    leftButton.size = CGSizeMake(20, 20);
//    [leftButton setImage:[UIImage imageNamed:@"Back-Arrow"] forState:UIControlStateNormal];
//    [leftButton addTarget:self action:@selector(clickMenu) forControlEvents:UIControlEventTouchUpInside];
//    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
//    self.navigationItem.leftBarButtonItem = leftItem;
    
    [[EMClient sharedClient].chatManager addDelegate:self delegateQueue:nil];

    self.tableView.emptyDataSetDelegate = self;
    self.tableView.emptyDataSetSource = self;
}


- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView{
    return [UIImage imageNamed:@"消息提示灰色"];
}
- (NSAttributedString *)buttonTitleForEmptyDataSet:(UIScrollView *)scrollView forState:(UIControlState)state{
    NSString *text = nil;
    UIFont *font = nil;
    UIColor *textColor = nil;
    text = @"去趣聊看看吧！";
    font = CustomUIFont(16);
    textColor = MainColor;
    NSMutableDictionary *attributes = [NSMutableDictionary new];
    if (font) [attributes setObject:font forKey:NSFontAttributeName];
    if (textColor) [attributes setObject:textColor forKey:NSForegroundColorAttributeName];
    
    return [[NSAttributedString alloc] initWithString:text attributes:attributes];
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        EaseConversationModel *model = [self.dataArray objectAtIndex:indexPath.row];
        [[EMClient sharedClient].chatManager deleteConversation:model.conversation.conversationId isDeleteMessages:YES completion:nil];
        [self.dataArray removeObjectAtIndex:indexPath.row];
        [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
        [tableView reloadEmptyDataSet];

    }
}

#pragma mark 清空回话列表
- (void)deleteAllContentList{
    [[EMClient sharedClient].chatManager deleteConversations:self.dataArray isDeleteMessages:YES completion:nil];
    [self.dataArray removeAllObjects];
    [self.tableView reloadData];

}

- (void)didReceiveMessages:(NSArray *)aMessages
{
    [self refreshAndSortView];
}

- (void)clickMenu{
    [self.navigationController popViewControllerAnimated:YES];
}




#pragma mark - DZNEmptyDataSetDelegate Methods

- (void)emptyDataSet:(UIScrollView *)scrollView didTapButton:(UIButton *)button
{
    self.tabBarController.selectedIndex = 2;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
